const fs = require('fs');
const zlib = require('zlib');

//流操作
let rs = fs.createReadStream('1.txt');
let gz = zlib.createGzip()
let ws = fs.createWriteStream('2.txt.gz');

rs.pipe(gz).pipe(ws)

rs.on('error', err => {
  console.log(err)
})

ws.on('finish', () => {
  console.log('完成');
})